/**
 * Created by meiguizhinian on 2018/7/16
 * Copyright © 2018 lixiaolong. All rights reserved.
 */

//单例/全静态/枚举
ivy.ParticleDataManager = {
	getInstance: function () {
		return this;
	},

	getParticleDatas : function() {
		return this._particleDatas;
	},
	getParticleGroupCount : function() {
		return this._particleGroupCount;
	},
	getParticleCount : function(groupID) {
		return this._particleDatas[groupID].length;
	},
	getParticleData(groupID, particleID) {
		return this._particleDatas[groupID][particleID];
	},
	checkParticleFlag(groupID, particleID, flag) {
		return (this._particleDatas[groupID][particleID].particleDatas[ivy.ParticleDataManager.ParticleDataType.eFlagValue] & flag) === flag;
	},
	initWithFile : function(path) {
		let is = new ivy.InputStream(path);
		let length = is.readJInt16();
		for (let i = 0; i < length; ++i) {
			let length1 = is.readJInt16();
			for (let j = 0; j < length1; ++j)
			{
				let id = is.readJInt16();
				let fre = is.readJInt16();
				let bCount = is.readJInt16();
			}
		}

		this._particleGroupCount = is.readJInt16();
		this._particleDatas = [];
		for (let i = 0; i < this._particleGroupCount; ++i) {
			let l = is.readJInt16();
			this._particleDatas[i] = [];
			for (let j = 0; j < l; ++j) {
				for (let k = 0; k < 18; ++k) {
					if (k === 1) {
						this._particleDatas[i][j].className = is.readStringUTF8();
					} else {
						this._particleDatas[i][j].particleDatas.push(is.readJInt16());
					}
				}
			}
		}
	},
	getParticleValueMapBy : function(fileName) {
		if (!this._particleMap.has(fileName)) {
			this._particleMap.set(fileName, cc.FileUtils.getInstance().getValueMapFromFile(fileName));
		}
		return this._particleMap.get(fileName);
	},
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////private:
	_particleGroupCount : 0,
	_particleDatas : [],//std::vector<std::vector<ParticleUnit>>
	_particleMap : new LLDictionary(),//std::map<std::string, cocos2d::ValueMap>
};

ivy.ParticleDataManager.ParticleDataType = {
	eTypeValue      : 0,
	eActionIDVlaue  : 1,
	ePowerValue     : 2,
	eAngleValue     : 3,
	eSpeedValue     : 4,
	eEffectIDValue  : 5,
	eASpeedValue    : 6,
	eOffsetXValue   : 7,
	eOffsetYValue   : 8,
	eFlagValue      : 9,
	eDelayValue     : 10,
	eRadiusValue    : 11,
	eRadiusAddValue : 12,
	eBackUp1        : 13,
	eBackUp2        : 14,
	eBackUp3        : 15,
	eBackUp4        : 16,
};

ivy.ParticleDataManager.ParticleFlagType = {
	eBackUp     : 1<<0,//备用
	eNeverDie   : 1<<1,//永远不死
	eFollow     : 1<<2,//是否跟随
	eCounteract : 1<<3,//是否抵消
	eCircle     : 1<<4,//是否循环播放
	eCollide    : 1<<5,//是否碰撞
};

(function(){
	ivy.ParticleDataManager.ParticleUnit = function () {
		//成员变量
		this.className = "";
		this.particleDatas = [];
	};
})();

